//
// Created by DP on 2025/9/15.
//
#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <stack>
#include <vector>
#include <set>
#include <unordered_set>
using namespace std;
#define ll long long


//https://codefun2000.com/p/P3486  双端队列 求极值 单调队列保留极值
void queue1() {
    int n;
    cin>>n;
    vector<int> temperatures(n);
    for (int i=0;i<n;i++) {
        cin>>temperatures[i];
    }
    //legal range 18-24
    //max-min <=4   unordedmap
    //滑动窗口
    //单调队列维护最大值最小值
    int l=0;
    vector<pair<int,int>> ans;
    int bestlen1=0;
    deque<int> qmin,qmax;
    for (int r=0;r<n;r++) {
        int v = temperatures[r];
        if (v<18||v>24) {
            qmin.clear();
            qmax.clear();
            l=r+1;
            continue;
        }
        //维护单调队列
        while (!qmin.empty()&&temperatures[qmin.back()]>=v) {
            qmin.pop_back();
        }
        qmin.push_back(r);
        while (!qmax.empty()&&temperatures[qmax.back()]<=v) {
            qmax.pop_back();
        }
        qmax.push_back(r);
        //收缩只到满足条件
        while (!qmin.empty()&&!qmax.empty()&& temperatures[qmax.front()]-temperatures[qmin.front()]>4) {
            if (qmin.front()==l) qmin.pop_front();
            if (qmax.front()==l) qmax.pop_front();
            l++;
        }

        //记录答案
        int len =r-l+1;
        if (len>0) {
            if (len>bestlen1) {
                bestlen1=len;
                ans.clear();
                ans.push_back({l,r});
            }else if (len == bestlen1) {
                ans.push_back({l,r});
            }
        }

    }
    for (auto c:ans) {
        cout<<c.first<<" "<<c.second<<endl;
    }
}
//https://codefun2000.com/p/P3310  使用两个队列 每次大循环判断的是两个队列是否有为空的 小循环相当于对索取的队伍进行一次遍历
int queue2() {
    string s;
    getline(cin,s);
    stringstream ss(s);
    vector<int> cars;
    string temp;
    while (getline(ss, temp, ' ')) {
        if (stoi(temp)>100||stoi(temp)<1) {
            cout<<-1<<endl;
            return 0;
        }
        cars.push_back(stoi(temp));
    }

    getline(cin,s);
    stringstream ss2(s);
    vector<int> q;
    while (getline(ss2, temp, ' ')) {
        if (stoi(temp)<1||stoi(temp)>100) {
            cout<<-1<<endl;
            return 0;
        }
        q.push_back(stoi(temp));
    }
    if (cars.size()>1000||cars.size()<1||q.size()>1000) {
        cout<<-1<<endl;
        return 0;
    }

    deque<int> qcar(cars.begin(),cars.end()),qq(q.begin(),q.end());

    while (!qcar.empty()&&!qq.empty()) {
        int k=qcar.front();
        qcar.pop_front();
        int attempt=qq.size();

        bool fed=false  ;
        while (attempt--) {
            if (qq.front()<=k) {
                int sum=0;
                while (!qq.empty()&&sum+qq.front()<=k) {
                    sum+=qq.front();
                    qq.pop_front();
                }
                fed=true;
                break;
            }else {
                int v= qq.front();
                qq.pop_front();
                qq.push_back(v);
            }
        }

    }
    cout<<qq.size()<<endl;
}
//https://codefun2000.com/p/P2316
// https://codefun2000.com/p/P2350


//优先队列
//https://codefun2000.com/p/P2270
//https://codefun2000.com/p/P2376
//https://codefun2000.com/p/P2926
//中等
//https://codefun2000.com/p/P3309
//https://codefun2000.com/p/P2972
//https://codefun2000.com/p/P2957
//https://codefun2000.com/p/P2348
//https://codefun2000.com/p/P2348



